package main

import "fmt"

func printSlice(s []int) {
	fmt.Printf("%v, len=%d, cap=%d\n", s, len(s), cap(s))
}

func main() {
	var s []int //Zero value for slice is nil
	fmt.Println(s)
	for i := 0; i < 2; i++ {
		printSlice(s)
		s = append(s, 2*i+1)
		/*
			todo
			append会使slice的容量成倍的增加, 当容量大于1000时1.25倍增加 2,4,8,16...1024, 1280,1696
		*/
	}
	fmt.Println(s)
	s1 := []int{2, 4, 6, 8}
	printSlice(s1)            //len=cap=4
	s2 := make([]int, 16)     //len=cap=16
	s3 := make([]int, 10, 32) //len=10, cap=32
	printSlice(s2)
	printSlice(s3)

	fmt.Println("Copying Slice")
	copy(s2, s1)
	printSlice(s2)

	fmt.Println("Deleting elements from slice")
	// 删除s2[3]    s2[:3] + s2[4:]
	s2 = append(s2[:3], s2[4:]...)
	printSlice(s2)

	fmt.Println("Popping from front")
	front := s2[0]
	s2 = s2[1:]
	fmt.Println(front)
	printSlice(s2)

	fmt.Println("Popping from end")
	tail := s2[len(s2)-1]
	s2 = s2[:len(s2)-1]
	fmt.Println(tail)
	printSlice(s2)
}
